package cn.jdy.djgaj.sevice;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.hibernate.SQLQuery;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.hibernate.transform.Transformers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.jdy.djgaj.entity.DjgajNews;
import cn.jdy.framework.db.hibernate.BaseDao;
import cn.jdy.framework.util.StringUtil;
import cn.jdy.platform.entity.ConfValue;
import cn.jdy.platform.service.ConfService;

/**
 * @desc   新闻操作类
 * @author ningqian
 * @date   2016-10-26
 */
@Service
public class DjgajNewsService extends BaseDao<DjgajNews> {

	@Autowired
	private ConfService confService;

	/**
	 * 按条件查询
	 * @param news
	 * @return
	 */
	public List<DjgajNews> query(DjgajNews news, String... date) {
		if(news == null) return super.findAll();
		//return super.find(createFilter(news, news.getiDisplayLength() > 0, date));
		if(news.getiDisplayLength() > 0){
//			原news
			//			return super.find(createFilter(news, date),news.getiDisplayStart(),news.getiDisplayLength());
			
			//现  公安局 将投稿的部门加入到news的username中
			List<DjgajNews> rs= super.find(createFilter(news, date),news.getiDisplayStart(),news.getiDisplayLength());
			  List<DjgajNews> rtn=new ArrayList<DjgajNews>();
			  int lens = rs.size();
			  for(int i=0;i<lens;i++){
				  DjgajNews tnews = rs.get(i);
				  if(tnews.getUsername()==null){
						String temp=tnews.getDepartment();
						tnews.setUsername(temp);
					  }
				  rtn.add(i, tnews);
			  }
			  return rtn;
		}
		return super.find(createFilter(news, date));
	}

	public Long count(DjgajNews news, String... date) {
		return super.count(createFilter(news, date));
	}
	/**
	 * 拼装条件
	 * @param news
	 * @param page
	 * @return
	 */
	private DetachedCriteria createFilter(DjgajNews news, String... date) {
	  DetachedCriteria dc = DetachedCriteria.forClass(entityClass);
	  if(!StringUtil.isNullOrEmpty(news.getKeywords())) {
      if(!StringUtil.isNullOrEmpty(news.getKeyType())) {
        dc.add(Restrictions.like(news.getKeyType(), news.getKeywords().trim(),MatchMode.ANYWHERE));
      }else
        //TODO 添加模糊搜索
        ;
    }
	  if(date.length>0 && !StringUtil.isNullOrEmpty(date[0]) && !StringUtil.isNullOrEmpty(date[1])){
		  dc.add(Restrictions.between("falseCreateTime", date[0],date[1]));
	  }
	  if(!StringUtil.isNullOrEmpty(news.getStatus())){
	    dc.add(Restrictions.eq("status", news.getStatus()));
	  }
	  if(news.getColumnId()!=null && news.getColumnId()>0){
		  List<ConfValue> list = confService.findConfValueByPid(news.getColumnId());
		  if(list!=null && list.size()>0) {
			  int size = list.size();
			  Long[] ids = new Long[size];
			  for(int i=0; i<size; i++) {
				  ids[i] = list.get(i).getId();
			  }
			  dc.add(Restrictions.in("columnId", ids));
		  }else {
			  dc.add(Restrictions.eq("columnId", news.getColumnId()));
		  }
	  }
	  if(!StringUtil.isNullOrEmpty(news.getUserid())){
      dc.add(Restrictions.eq("userid", news.getUserid()));
    }
	  if(!StringUtil.isNullOrEmpty(news.getSortType())) {
	    dc.addOrder(Order.desc("sortType"));
	  }
	  //新增去掉投稿，即状态=0的news
	//  dc.add(Restrictions.or(Restrictions.eq("status", "1"),Restrictions.eq("status", "2"),Restrictions.eq("status", "3"),Restrictions.eq("status", "4"),Restrictions.eq("status", "5"),Restrictions.eq("status", "6"),Restrictions.eq("status", "7"),Restrictions.eq("status", "8")));
	  dc.addOrder(Order.desc("topTime"));
	  dc.addOrder(Order.desc("falseCreateTime"));
		return dc;
	}

	/**
	 * 查询热门新闻
	 * @return
	 */
	public List<DjgajNews> queryHotNews() {
		DetachedCriteria dc = DetachedCriteria.forClass(entityClass);
		dc.add(Restrictions.eq("status", "1"));//前台查询需展示有效状态文章
    dc.addOrder(Order.desc("readTimes"));
    return super.find(dc,0,5);
		
	}
	
	/**
	 * @since 040116
	 * 模糊查询新闻
	 * @return
	 * 加入columnId
	 */
	public List<DjgajNews> queryByLike(DjgajNews news,String keywords) {
	  DetachedCriteria dc = DetachedCriteria.forClass(entityClass);
	  dc.add(Restrictions.eq("status", news.getStatus()));//前台查询需展示有效状态文章
	  dc.add(Restrictions.or(
	      Restrictions.like("title", keywords, MatchMode.ANYWHERE),
	      Restrictions.like("keyword", keywords, MatchMode.ANYWHERE),
	      Restrictions.like("summary", keywords, MatchMode.ANYWHERE),
	      Restrictions.like("context", keywords, MatchMode.ANYWHERE)
	  ));
	  if(news.getColumnId()!=null){
		  dc.add(Restrictions.eq("columnId", news.getColumnId()));
	  }
	  if(news.getIscolums()!=null){
		  dc.add(Restrictions.eq("iscolums", news.getIscolums()));
	  }
	  dc.addOrder(Order.desc("topTime"));
	  dc.addOrder(Order.desc("falseCreateTime"));
	  return super.find(dc,news.getiDisplayStart(),news.getiDisplayLength());
	}
	
	/**
	 * 模糊查询新闻
	 * @return
	 */
	public int queryByLikeCount(DjgajNews news,String keywords) {
	  DetachedCriteria dc = DetachedCriteria.forClass(entityClass);
	  dc.add(Restrictions.eq("status", news.getStatus()));//前台查询需展示有效状态文章
	  dc.add(Restrictions.or(
	      Restrictions.like("title", keywords, MatchMode.ANYWHERE),
	      Restrictions.like("keyword", keywords, MatchMode.ANYWHERE),
	      Restrictions.like("summary", keywords, MatchMode.ANYWHERE),
	      Restrictions.like("context", keywords, MatchMode.ANYWHERE)
	  ));
	  if(news.getIscolums()!=null){
		  dc.add(Restrictions.eq("iscolums", news.getIscolums()));
	  }
	  dc.addOrder(Order.desc("falseCreateTime"));
	  return super.find(dc).size();
	}

	/**
	 * 按照类型查询 文章
	 * @return
	 */
	public List<DjgajNews> findbytype(Long columnid,int firstResult, int maxResults, boolean isImg) {
	  DetachedCriteria dc = DetachedCriteria.forClass(entityClass);
//	  前台查询需展示有效/置顶状态的文章
	  dc.add(Restrictions.or(Restrictions.eq("status", "1"),Restrictions.eq("status", "5"),Restrictions.eq("status", "6"),Restrictions.eq("status", "7")));
//	  dc.add(Restrictions.eq("status", "1"));//前台查询需展示有效状态文章
	  if(null != columnid){
	    dc.add(Restrictions.eq("columnId", columnid));
	  }
	  if(isImg){// 是否有封面图片
	    dc.add(Restrictions.ne("imgUrl", ""));
	  }
	  dc.addOrder(Order.desc("topTime"));
	  dc.addOrder(Order.desc("falseCreateTime"));
	  return super.find(dc, firstResult, maxResults);
	}
	
	/**
	 * 按照大分类 查询 文章
	 * @return
	 */
	public List<DjgajNews> findbyPid(Long pid,int firstResult, int maxResults, boolean isImg) {
	  DetachedCriteria dc = DetachedCriteria.forClass(entityClass);
	  dc.createAlias("cv", "cv");
//	  前台查询需展示有效/置顶状态的文章
//	  dc.add(Restrictions.or(Restrictions.eq("status", "1"),Restrictions.eq("status", "3")));
	  dc.add(Restrictions.eq("status", "1"));//前台查询需展示有效状态文章
	  if(isImg){// 是否有封面图片
	    dc.add(Restrictions.ne("imgUrl", ""));
    }
	  if(null != pid){
	    dc.add(Restrictions.eq("cv.pid", pid));
	  }
	  dc.addOrder(Order.desc("topTime"));
	  dc.addOrder(Order.desc("falseCreateTime"));
	  return super.find(dc,firstResult,maxResults);
	}
	
	/**
	 * 站点地图
	 * @return
	 */
	public List<Map<String, String>> querySiteMap(int start,int limit) {
	  String sql = "select id,title,createTime from "+entityClass.getSimpleName()+" where status =1 limit ?,?";
    SQLQuery sqlQuery = super.em().createSQLQuery(sql);
    sqlQuery.setParameter(0, start);
    sqlQuery.setParameter(1, limit);
    // 将查询寻结果转换为Map格式，解决多表查询或零散字段查询 映射取值问题
    sqlQuery.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
    return sqlQuery.list();
	}
 
	/**
	 * 查询置顶新闻
	 * @return
	 */
	public List<DjgajNews> queryStickieNews() {
		DetachedCriteria dc = DetachedCriteria.forClass(entityClass);
		dc.add(Restrictions.eq("status", "3"));//查询置顶状态的文章
    dc.addOrder(Order.desc("readTimes"));
    return super.find(dc,0,5);
	}
	
	/**
	 * 按照类型查询 文章
	 * @return
	 */
	public List<DjgajNews> findbytypeNstatus(Long columnid,int firstResult, int maxResults, boolean isImg, int isStickied) {
	  DetachedCriteria dc = DetachedCriteria.forClass(entityClass);
//	  前台查询需展示有效/置顶状态的文章
//	  dc.add(Restrictions.or(Restrictions.eq("status", "1"),Restrictions.eq("status", "3")));
	  dc.add(Restrictions.eq("status", "3"));//仅查询置顶状态-实际上仅一条
	  if(null != columnid){
	    dc.add(Restrictions.eq("columnId", columnid));
	  }
	  if(isImg){// 是否有封面图片
	    dc.add(Restrictions.ne("imgUrl", ""));
	  }
	  dc.addOrder(Order.desc("topTime"));
	  dc.addOrder(Order.desc("falseCreateTime"));
	  return super.find(dc, firstResult, maxResults);
	}
	
	/**
	 * 根据发布单位查询
	 * @param n
	 * @return
	 */
	public Map<String, Object> getNum() {
		Map<String, Object> map = new HashMap<String, Object>();
	    String sql = "SELECT COUNT(id)  FROM news GROUP BY userName ORDER BY COUNT(id) DESC LIMIT 0,3";
	    SQLQuery query = super.em().createSQLQuery(sql.toString());
	    map.put("dataList", query.list());
	    return map;
	  }
	public Map<String, Object> getApr() {
		Map<String, Object> map = new HashMap<String, Object>();
	    String sql = "SELECT userName FROM news GROUP BY userName ORDER BY COUNT(id) DESC LIMIT 0,3";
	    SQLQuery query = super.em().createSQLQuery(sql.toString());
	    map.put("dataList", query.list());
	    return map;
	  }
	/**
	 * 
	 * @return
	 */
	public Map<String, Object> getids(int columnId) {
		Map<String, Object> map = new HashMap<String, Object>();
	    String sql = "SELECT id FROM news WHERE columnId='"+columnId+"' AND transforms IS NULL";
	    SQLQuery query = super.em().createSQLQuery(sql.toString());
	    map.put("dataList", query.list());
	    return map;
	  }
	
	public Map<String, Object> getdeps(int columnId) {
		Map<String, Object> map = new HashMap<String, Object>();
	    String sql = "SELECT depars FROM news WHERE columnId='"+columnId+"' AND transforms IS NULL";
	    SQLQuery query = super.em().createSQLQuery(sql.toString());
	    map.put("dataList", query.list());
	    return map;
	  }
//	public Map<String, Object> setids(int ids) {
//		Map<String, Object> map = new HashMap<String, Object>();
//	    String sql = "INSERT INTO Associations(id) VALUE ("+ids+")";
//	    SQLQuery query = super.em().createSQLQuery(sql.toString());
//	    map.put("dataList", query.list());
//	    return map;
//	  }
//	public Map<String, Object> setdeps(int columnId) {
//		Map<String, Object> map = new HashMap<String, Object>();
//	    String sql = "SELECT departments FROM news WHERE columnId='"+columnId+"'";
//	    SQLQuery query = super.em().createSQLQuery(sql.toString());
//	    map.put("dataList", query.list());
//	    return map;
//	  }
	/**
	 * 根据辖区查询
	 * @param n
	 * @return
	 */
	public Map<String, Object> getNumLoc() {
		Map<String, Object> map = new HashMap<String, Object>();
	    String sql = "SELECT COUNT(id)  FROM news GROUP BY locations ORDER BY COUNT(id) DESC LIMIT 0,3";
	    SQLQuery query = super.em().createSQLQuery(sql.toString());
	    map.put("dataList", query.list());
	    return map;
	  }
	public Map<String, Object> getAprLoc() {
		Map<String, Object> map = new HashMap<String, Object>();
	    String sql = "SELECT locations FROM news GROUP BY locations ORDER BY COUNT(id) DESC LIMIT 0,3";
	    SQLQuery query = super.em().createSQLQuery(sql.toString());
	    map.put("dataList", query.list());
	    return map;
	  }
	
	
	//投稿修改
	/**
	 * 按条件查询
	 * @param news
	 * @return
	 */
	public List<DjgajNews> query1(DjgajNews news, String... date) {
		if(news == null) return super.findAll();
		//return super.find(createFilter(news, news.getiDisplayLength() > 0, date));
		if(news.getiDisplayLength() > 0){
			return super.find(createFilter1(news, date),news.getiDisplayStart(),news.getiDisplayLength());
			//公安局 将投稿的部门加入到news的username中
		  /*List<News> rs= super.find(createFilter1(news, date),news.getiDisplayStart(),news.getiDisplayLength());
		  List<News> rtn=new ArrayList<News>();
		  int lens = rs.size();
		  for(int i=0;i<lens;i++){
			  News tnews = rs.get(i);
//			  if(tnews.getUsername()==null){
//					String[] temp=tnews.getDepartments();
//					int tlen = temp.length;
//					String un = null;
//					for(int i1=0;i1<tlen;i1++){
//						if(temp[i1]!=null&&temp[i1]!=""){
//							un = temp[i1]+" ";
//						}
//					}
//					tnews.setUsername(un);
//				  }
			  rtn.add(i, tnews);
		  }
		  return rtn;*/
		}
		return super.find(createFilter1(news, date));
	}

	public Long count1(DjgajNews news, String... date) {
		return super.count(createFilter1(news, date));
	}
	/**
	 * 拼装条件
	 * @param news
	 * @param page
	 * @return
	 */
	private DetachedCriteria createFilter1(DjgajNews news, String... date) {
	  DetachedCriteria dc = DetachedCriteria.forClass(entityClass);
	  if(!StringUtil.isNullOrEmpty(news.getKeywords())) {
      if(!StringUtil.isNullOrEmpty(news.getKeyType())) {
        dc.add(Restrictions.like(news.getKeyType(), news.getKeywords().trim(),MatchMode.ANYWHERE));
      }else
        //TODO 添加模糊搜索
        ;
    }
	  if(date.length>0 && !StringUtil.isNullOrEmpty(date[0]) && !StringUtil.isNullOrEmpty(date[1])){
	    dc.add(Restrictions.between("falseCreateTime", date[0],date[1]));
	  }
	  if(!StringUtil.isNullOrEmpty(news.getStatus())){
	    dc.add(Restrictions.eq("status", news.getStatus()));
	  }
	  if(news.getColumnId()!=null && news.getColumnId()>0){
		  List<ConfValue> list = confService.findConfValueByPid(news.getColumnId());
		  if(list!=null && list.size()>0) {
			  int size = list.size();
			  Long[] ids = new Long[size];
			  for(int i=0; i<size; i++) {
				  ids[i] = list.get(i).getId();
			  }
			  dc.add(Restrictions.in("columnId", ids));
		  }else {
			  dc.add(Restrictions.eq("columnId", news.getColumnId()));
		  }
	  }
	  if(!StringUtil.isNullOrEmpty(news.getUserid())){
      dc.add(Restrictions.eq("userid", news.getUserid()));
      }
	  if(!StringUtil.isNullOrEmpty(news.getSortType())) {
	    dc.addOrder(Order.desc("sortType"));
	  }
	  //新增去掉投稿，即状态=0的news
	  dc.addOrder(Order.desc("topTime"));
	  dc.addOrder(Order.desc("falseCreateTime"));
		return dc;
	}

	
	public List<DjgajNews> query2(DjgajNews news, String... date) {
		if(news == null) return super.findAll();
		//return super.find(createFilter(news, news.getiDisplayLength() > 0, date));
		if(news.getiDisplayLength() > 0){
			return super.find(createFilter2(news, date),news.getiDisplayStart(),news.getiDisplayLength());
			//公安局 将投稿的部门加入到news的username中
		  /*List<News> rs= super.find(createFilter1(news, date),news.getiDisplayStart(),news.getiDisplayLength());
		  List<News> rtn=new ArrayList<News>();
		  int lens = rs.size();
		  for(int i=0;i<lens;i++){
			  News tnews = rs.get(i);
//			  if(tnews.getUsername()==null){
//					String[] temp=tnews.getDepartments();
//					int tlen = temp.length;
//					String un = null;
//					for(int i1=0;i1<tlen;i1++){
//						if(temp[i1]!=null&&temp[i1]!=""){
//							un = temp[i1]+" ";
//						}
//					}
//					tnews.setUsername(un);
//				  }
			  rtn.add(i, tnews);
		  }
		  return rtn;*/
		}
		return super.find(createFilter2(news, date));
	}

	public Long count2(DjgajNews news, String... date) {
		return super.count(createFilter2(news, date));
	}
	/**
	 * 拼装条件
	 * @param news
	 * @param page
	 * @return
	 */
	private DetachedCriteria createFilter2(DjgajNews news, String... date) {
	  DetachedCriteria dc = DetachedCriteria.forClass(entityClass);
	  if(!StringUtil.isNullOrEmpty(news.getKeywords())) {
      if(!StringUtil.isNullOrEmpty(news.getKeyType())) {
        dc.add(Restrictions.like(news.getKeyType(), news.getKeywords().trim(),MatchMode.ANYWHERE));
      }else
        //TODO 添加模糊搜索
        ;
    }
	  if(date.length>0 && !StringUtil.isNullOrEmpty(date[0]) && !StringUtil.isNullOrEmpty(date[1])){
	    dc.add(Restrictions.between("falseCreateTime", date[0],date[1]));
	  }
	  if(!StringUtil.isNullOrEmpty(news.getStatus())){
	    dc.add(Restrictions.eq("status", news.getStatus()));
	  }
	  if(news.getColumnId()!=null && news.getColumnId()>0){
		  List<ConfValue> list = confService.findConfValueByPid(news.getColumnId());
		  if(list!=null && list.size()>0) {
			  int size = list.size();
			  Long[] ids = new Long[size];
			  for(int i=0; i<size; i++) {
				  ids[i] = list.get(i).getId();
			  }
			  dc.add(Restrictions.in("columnId", ids));
		  }else {
			  dc.add(Restrictions.eq("columnId", news.getColumnId()));
		  }
	  }
	  if(!StringUtil.isNullOrEmpty(news.getUserid())){
      dc.add(Restrictions.eq("userid", news.getUserid()));
      }
	  if(!StringUtil.isNullOrEmpty(news.getIscolums())){
	      dc.add(Restrictions.eq("iscolums", news.getIscolums()));
	      }
	  if(!StringUtil.isNullOrEmpty(news.getSortType())) {
	    dc.addOrder(Order.desc("sortType"));
	  }
	  //新增去掉投稿，即状态=0的news
	  dc.addOrder(Order.desc("topTime"));
	  dc.addOrder(Order.desc("falseCreateTime"));
		return dc;
	}
	
	public List<DjgajNews> findbyNstatus(Long columnid,int firstResult, int maxResults, boolean isImg, int isStickied) {
		  DetachedCriteria dc = DetachedCriteria.forClass(entityClass);
//		  前台查询需展示有效/置顶状态的文章
		  dc.add(Restrictions.or(Restrictions.eq("status", "1"),Restrictions.eq("status", "3")));
		  if(null != columnid){
		    dc.add(Restrictions.eq("columnId", columnid));
		  }
		  dc.add(Restrictions.or(Restrictions.ne("imgUrl", ""),Restrictions.ne("imgUrl", null)));
		  dc.addOrder(Order.desc("topTime"));
		  dc.addOrder(Order.desc("falseCreateTime"));
		  return super.find(dc, firstResult, maxResults);
		}
	
	/**
	 * 按条件查询:查询除status=0之外的其他状态的有效信息
	 * @param Notice
	 * @return
	 */
	public List<DjgajNews> queryTa(DjgajNews columns, String... date) {
		if(columns == null) return super.findAll();
		//return super.find(createFilter(Notice, Notice.getiDisplayLength() > 0, date));
		if(columns.getiDisplayLength() > 0){
		  return super.find(createFilterTa(columns, date),columns.getiDisplayStart(),columns.getiDisplayLength());
		}
		return super.find(createFilterTa(columns, date));
	}

	public Long countTa(DjgajNews columns, String... date) {
		return super.count(createFilterTa(columns, date));
	}
	
	/**
	 * 拼装条件
	 * @param Notice
	 * @param page
	 * @return
	 */
	private DetachedCriteria createFilterTa(DjgajNews columns, String... date) {
	  DetachedCriteria dc = DetachedCriteria.forClass(entityClass);
	  if(!StringUtil.isNullOrEmpty(columns.getKeywords())) {
      if(!StringUtil.isNullOrEmpty(columns.getKeyType())) {
        dc.add(Restrictions.like(columns.getKeyType(), columns.getKeywords().trim(),MatchMode.ANYWHERE));
      }else
        //TODO 添加模糊搜索
        ;
    }
	  if(date.length>0 && !StringUtil.isNullOrEmpty(date[0]) && !StringUtil.isNullOrEmpty(date[1])){
	    dc.add(Restrictions.between("falseCreateTime", date[0],date[1]));
	  }
	  if(!StringUtil.isNullOrEmpty(columns.getUserid())){
      dc.add(Restrictions.eq("userid", columns.getUserid()));
    }
	  if(!StringUtil.isNullOrEmpty(columns.getSortType())) {
	    dc.addOrder(Order.desc("sortType"));
	  }
	  if(!StringUtil.isNullOrEmpty(columns.getStatus())) {
		    dc.add(Restrictions.eq("status", columns.getStatus()));
		  }
	  if(!StringUtil.isNullOrEmpty(columns.getIscolums())) {
		    dc.add(Restrictions.eq("iscolums", columns.getIscolums()));
		  }
	//  dc.add(Restrictions.or(Restrictions.eq("status", "5"),Restrictions.eq("status", "6"),Restrictions.eq("status", "7")));
	  dc.addOrder(Order.desc("topTime"));
	  dc.addOrder(Order.desc("falseCreateTime"));
		return dc;
	}
	
	/**
	 * 查询置顶前八条
	 * @return
	 */
	public List<DjgajNews> queryTopOne() {
		DetachedCriteria dc = DetachedCriteria.forClass(entityClass);
		dc.add(Restrictions.eq("beTopString", "1"));
		  dc.addOrder(Order.desc("topTime"));
		dc.addOrder(Order.desc("falseCreateTime"));
		return super.find(dc,0,8);
	}
	/**
	 * 按条件查询:查询除置顶之外的其他有效信息
	 * @param Notice
	 * @return
	 */
	public List<DjgajNews> queryTop(DjgajNews columns, String... date) {
		if(columns == null) return super.findAll();
		//return super.find(createFilter(Notice, Notice.getiDisplayLength() > 0, date));
		if(columns.getiDisplayLength() > 0){
		  return super.find(createFilterTop(columns, date),columns.getiDisplayStart(),columns.getiDisplayLength());
		}
		return super.find(createFilterTop(columns, date));
	}
	
	/**
	 * 拼装条件
	 * @param Notice
	 * @param page
	 * @return
	 */
	private DetachedCriteria createFilterTop(DjgajNews columns, String... date) {
	  DetachedCriteria dc = DetachedCriteria.forClass(entityClass);
	  if(!StringUtil.isNullOrEmpty(columns.getKeywords())) {
      if(!StringUtil.isNullOrEmpty(columns.getKeyType())) {
        dc.add(Restrictions.like(columns.getKeyType(), columns.getKeywords().trim(),MatchMode.ANYWHERE));
      }else
        //TODO 添加模糊搜索
        ;
    }
	  if(date.length>0 && !StringUtil.isNullOrEmpty(date[0]) && !StringUtil.isNullOrEmpty(date[1])){
	    dc.add(Restrictions.between("falseCreateTime", date[0],date[1]));
	  }
//	  if(!StringUtil.isNullOrEmpty(columns.getBeTopString())){
	  //  dc.add(Restrictions.ne("beTopString", "1"));
//	  }
	  if(!StringUtil.isNullOrEmpty(columns.getUserid())){
      dc.add(Restrictions.eq("userid", columns.getUserid()));
    }
	  if(!StringUtil.isNullOrEmpty(columns.getSortType())) {
	    dc.addOrder(Order.desc("sortType"));
	  }
	  if(!StringUtil.isNullOrEmpty(columns.getStatus())) {
		  dc.add(Restrictions.eq("status", columns.getStatus()));
		  }
	  if(!StringUtil.isNullOrEmpty(columns.getIscolums())) {
		  dc.add(Restrictions.eq("iscolums", columns.getIscolums()));
		  }
	 // dc.add(Restrictions.or(Restrictions.eq("status", "5"),Restrictions.eq("status", "6"),Restrictions.eq("status", "7")));
	  dc.addOrder(Order.desc("topTime"));
	  dc.addOrder(Order.desc("falseCreateTime"));
		return dc;
	}
}
